import Md5 from 'js-md5'

function randomStr(length) {
  let result = '';
  const characters = '0123456789abcdefghijklmnopqrstuvwxyz';
  for (let i = 0; i < length; i++) {
    result += characters.charAt(Math.floor(Math.random() * characters.length));
  }
  return result;
}

const prefix = 'chx'
const suffix = 'sign'

export function generateSignHeader() {
    let timestamp = new Date().getTime();
    let nonceStr = randomStr(16);
    
    let sign = Md5(prefix + timestamp + "-" + nonceStr + "-" + suffix);
    return {
        timestamp: timestamp,
        nonceStr: nonceStr,
        sign: sign
    }
}